package com.wuwei.elearning.test.generator;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

import java.util.ArrayList;
import java.util.List;

@SpringBootTest
@ActiveProfiles("test")  //
public class CodeGenerator {

    @Test
    public void test() {
        ;
        List<String> list = new ArrayList<>();
        list.add("changed_log");
        FastAutoGenerator.create("jdbc:mysql://192.168.1.100:3306/e_learning_backup?allowPublicKeyRetrieval=true&useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai", "root", "123456")
                .globalConfig(builder -> builder
                        .author("wuwei")
                        .outputDir("D:\\e_learning\\e-learning-java\\src\\main\\java")
                        .commentDate("yyyy-MM-dd")
                )
                .packageConfig(builder -> builder
                        .parent("com.wuwei.elearning.question")
                        .entity("domain")
                        .mapper("mapper")
                        .service("service")
                        .serviceImpl("service.impl")
                        .xml("mapper.xml")
                )
                .strategyConfig(builder -> builder
                        .addInclude(list)
                        .entityBuilder()
                        .enableLombok()
                        .build() // 注意这里需要 build()
                        .serviceBuilder()
                        .formatServiceFileName("%sService") // 设置服务接口文件名格式
                        .formatServiceImplFileName("%sServiceImpl") // 设置服务实现类文件名格式
                        .build() // 注意这里需要 build()
                )
                .templateConfig(builder -> builder
                        .entity("templates/entityTemplate.vm") // Ensure the path is correct
                        .controller("templates/controller.vm") // 使用自定义的controller模板
                        .service("templates/service.vm") // 使用自定义的service模板
                )
                .templateEngine(new VelocityTemplateEngine()) // Use Velocity template engine
                .execute();
    }
}